package com.selfdriving.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.selfdriving.BaseApplication;
import com.selfdriving.utils.TextUtils;

public class JsonResolveUtils
{
	/** 首页VF数据 **/
	private static final String HOMEVF = "home.json";

	/** 解析首页VFJson数据 **/
	public static boolean resolveHomeVF(BaseApplication application)
	{
		if (application.homeList != null && application.homeList.isEmpty())
		{
			String json = TextUtils.getJson(
					application.getApplicationContext(), HOMEVF);
			if (json != null)
			{
				try
				{
					JSONArray array = new JSONArray(json);
					Home home = null;
					JSONObject object = null;
					for (int i = 0; i < array.length(); i++)
					{
						object = array.getJSONObject(i);
						String id = object.getString("id");
						String img = object.getString("img");
						home = new Home(id, img);
						application.homeList.add(home);
					}
				} catch (JSONException e)
				{
					e.printStackTrace();
					application.homeList.clear();
				}
			}
		}
		if (application.homeList.isEmpty())
		{
			return false;
		} else
		{
			return true;
		}
	}
}
